/**
 * @file implements MouseInput
 * @author CORSAIR <vladimir.corsair@gmail.com>
 * @version 2.1.4
 */

/** 
 * @param {Object} screen instance of screen object
 * @returns {MouseInput}
 */
var MouseInput = function (screen) {
    this.on = new EventSet();
    this.screen = screen;
    
    this.on.add('up');
    this.on.add('down');
    this.on.add('move');
    
    window.addEventListener('mouseup', this.fire.bind(this, 'up'));
    screen.canvas.addEventListener('mousedown', this.fire.bind(this, 'down'));
    screen.canvas.addEventListener('mousemove', this.fire.bind(this, 'move'));
    return this;
};

/**
 * This method fires the events
 * @param {String} name the name of the fired event
 * @param {Object} event the native mouse event
 * @returns {undefined}
 */
MouseInput.prototype.fire = function(name, event) {
    var info = this.screen.translate({
        which: event.which,
        time: (new Date()).getTime(),
        x: event.clientX,
        y: event.clientY
    });
    if (this.screen.innerPoint(info.x, info.y)) this.on.fire(name, info);
};

/**
 * Holds list of available mouse buttons
 * @static
 * @type Object
 */
MouseInput.mouseMap = {
    1: 'LMB',
    2: 'MMB',
    3: 'RMB'
};
